﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GreenArrow;
using System.Threading;
using System.IO;

namespace Marker
{
    public partial class Form1 : Form
    {
        Arrow arrow;
        bool onLeft = true;
        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (onLeft)
            {
                this.Left = Screen.PrimaryScreen.Bounds.Width - this.Width;
                onLeft = false;
            }
            else {
                this.Left = 0;
                onLeft = true;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Collapse();
            this.Left = 0;
            this.Top = 0;
            arrow = new Arrow(Directory.GetCurrentDirectory() + "/MarkerData");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            arrow.AutoNaming = checkBox1.Checked;
            if (arrow.AutoNaming)
            {
                this.Hide();
                string markerName = arrow.MarkRect();
                //Thread.Sleep(1000);
                //arrow.Click(markerName);
                this.Show();
            }
            else {
                Expand();
                markerNameTextBox.Text = "";
                markerNameTextBox.Focus();
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            StartMark();
        }
        void StartMark() {
            if (markerNameTextBox.Text.Length > 0)
            {
                arrow.MarkerName = markerNameTextBox.Text;
                Collapse();
                this.Hide();
                arrow.MarkRect();
                this.Show();
            }

        }
        void Collapse() {
            this.Height = button1.Top * 2 + button1.Height;
        }
        void Expand() {
            this.Height = markerNameTextBox.Top + markerNameTextBox.Height + button1.Top;
        }
        private void markerNameTextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13) {
                StartMark();
            }
        }
    }
}
